﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Security.Cryptography;
using Scheduling.Models.Helpers;
using System.Text.RegularExpressions;

namespace Scheduling.Models.Extensions
{
    public static class StringExtensions
    {
        public static string Hash(this string s)
        {
            s += Configuration.PasswordSalt;
            UnicodeEncoding UE = new UnicodeEncoding();
            byte[] hashValue;
            byte[] message = UE.GetBytes(s);

            SHA256Managed hashString = new SHA256Managed();
            string result = "";

            hashValue = hashString.ComputeHash(message);
            foreach (byte x in hashValue)
                result += String.Format("{0:x2}", x);

            return result;            
        }
        public static bool Match(this string s, string Pattern)
        {
            Regex re = new Regex(Pattern);
            return re.Match(s).Success;
        }
        public static string SqlFormat(this string s, params object[] input)
        {
            return string.Format(s, input);
        }
    }
}